home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13167 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  65 lines

  1. Path: mail2news.demon.co.uk!txwang
  2. From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Symantec 7.2 Hello World Problem
  5. Date: Sun, 24 Mar 1996 10:54:14 GMT
  6. Message-ID: <199603232309.HAA22808@public1.guangzhou.gd.cn>
  7. X-NNTP-Posting-Host: txwang
  8. X-Newsreader: Forte Free Agent 1.0.82
  9. X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
  10.  
  11. On Fri, 22 Mar 1996 10:02:55 -0500, Ron Romero <ron.romero@ssds.com>
  12. wrote:
  13.  
  14. | I'm having trouble doing a C++ Hello World program with Symantec C++ 7.2, using output to windows 
  15. | 3.11 console.  It seems like this should be trivial, but it dowsn't work.  It works with printf, 
  16. | but cout produces no output.  
  17.  
  18. | Here's the code:
  19.  
  20. | -----Cut Here------------
  21. | #include <iostream.h>
  22. | #include <stdio.h>
  23.  
  24. | main()
  25. | {
  26. |     cout << "Hello World" << endl;
  27.  
  28. |     printf("Goodbye World\n");
  29. | }
  30. | -----Cut Here------------
  31.  
  32. | This produces "Goodbye World" on the first line of the console window.  
  33.  
  34. | Any ideas?  Am I just not linking right?
  35.  
  36. | Ron Romero
  37.  
  38. Generally, you cannot mix cout and printf(), because both of them are
  39. bufferring outputs.
  40.  
  41. So, if you remove the printf(...), you'll see "Hello World" on the
  42. console.  If you insist to mix cout and printf(), try this:
  43.  
  44. #include <iostream.h>
  45. #include <stdio.h>
  46.  
  47. int main()
  48. {
  49.     cout << "Hello World" << endl;
  50.     cout.flush();
  51.     printf( "Goodbye World\n" );
  52.     fflush( stdout );
  53.     return 0;
  54. }
  55.  
  56. I believe this question is in the FAQ:
  57.  
  58.     ftp://rtmf.mit.edu/pub/usenet-by-group/comp.lang.c++/*
  59.  
  60.  
  61. ---
  62. Wang TianXing
  63.  
  64.  
  65.